<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    // 4. 控制 Generator 执行流
    //     Generator 允许你通过 next() 方法控制函数的执行。每次调用 next()，Generator 函数会恢复执行，
    //     并且可以通过 yield 返回一个新的值。
    function* countToFive() {
        console.log("Start");
        yield 1;
        console.log("After first yield");
        yield 2;
        console.log("After second yield");
        yield 3;
        yield 4;
        yield 5;
        console.log("End");
    }

    const counter = countToFive();

    console.log(counter.next());  // { value: 1, done: false }
    console.log(counter.next());  // { value: 2, done: false }
    console.log(counter.next());  // { value: 3, done: false }
    console.log(counter.next());  // { value: 4, done: false }
    console.log(counter.next());  // { value: 5, done: false }
    console.log(counter.next());  // { value: undefined, done: true }

</script>
</html>